//根据id获取文章信息
function getArticleInfo() {
    // console.log(window.location.search); //?id=219
    const id = (window.location.search).split('=')[1]
    // console.log(id);
    http.ajax({
        type: 'get',
        url: '/admin/article/search',
        data: { id },
        success: (res) => {
            // console.log(res);
            //对象解构
            const { title, cover, categoryId, date, content } = res.data;
            $('#inputTitle').val(title);
            $('.article_cover').prop('src', cover);
            $('.category').val(categoryId);
            $('#articleDate').val(date);
            $('#articleContent').val(content)
        }
    })
}

//获取文章分类
function getCategory() {
    http.ajax({
        type: 'get',
        url: '/admin/category/list',
        success: (res) => {
            // console.log(res);
            const renderRes = template('categoryTemplate', res);
            $('.category').html(renderRes)
            //因为获取文章分类和获取文章信息都是ajax请求，异步函数，所以要等文章分类渲染完再回显
            getArticleInfo();
        }
    })
}

//时间插件初始化
function initPlugin() {
    // 初始化日期插件
    jeDate("#articleDate", {
        format: "YYYY-MM-DD hh:mm:ss",
        isTime: true,
        minDate: "2014-09-19 00:00:00"
    })
};

//富文本资源初始化
tinymce.init({
    selector: '#articleContent',
    language: 'zh_CN',
})

getCategory();
initPlugin();